extends Area2D


signal shoot(pos)
var shoot_token = false
var new_shoot = false
@onready var body = $'body'

func _ready():
	body.play("idle")

func _process(delta):
	if not shoot_token:
		for zombie in get_parent().zombie_list:
			if abs(zombie.position.y - position.y) < 110 and zombie.on_ground \
			and zombie.position.x >= position.x - 50:
				shoot_token = true
				break
	elif shoot_token:
		if body.frame == 0:
			body.play("shoot")
			new_shoot = true
		if new_shoot and body.frame == 10:
			new_shoot = false
			shoot.emit(position + Vector2(35, -25))
		var token = true
		for zombie in get_parent().zombie_list:
			if abs(zombie.position.y - position.y) < 110:
				token = false
				break
		if token:
			shoot_token = false
			body.play("idle")

#var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

#func _physics_process(delta):
	#if not is_on_floor():
		#velocity.y += gravity
	#move_and_slide()

